package net.borlis.sample.service.db.em.lifecycle;

import net.borlis.sample.service.db.em.DatabaseDictionary;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;

/**
 * @author alex@borlis.net on 29.10.2014.
 */
@RequestScoped
public class LifecycleEntityManagerProvider implements ILifecycleEntityManagerProvider {

//    @Inject @Default
    private EntityManager entityManager;

    @Inject @WorkingCopy
    private EntityManager workingCopyEm;

    @Inject @WaitingForUploadCopy
    private EntityManager waitingForUploadCopyEm;

    @Inject @LiveCopy
    private EntityManager liveCopyEm;

    @Inject @LastLiveCopy
    private EntityManager lastLiveCopyEm;

//    @Inject @DeletedCopy
//    private EntityManager deletedCopyEm;

    public EntityManager provideLifecycleEntityManager(){
        return entityManager; // todo:: by default?
    }

    public EntityManager provideLifecycleEntityManager(DatabaseDictionary db){
        switch (db) {
            case CONFIGURATION_WORKING_COPY:  return workingCopyEm;
            case CONFIGURATION_WAITING_FOR_UPLOAD_COPY:  return waitingForUploadCopyEm;
            case CONFIGURATION_LIVE_COPY:  return liveCopyEm;
            case CONFIGURATION_LAST_LIVE_COPY:  return lastLiveCopyEm;
        }
        return workingCopyEm; // todo:: by default?
    }

}
